//
//  DLBChooseSceneView.m
//  HZDuoLaiBei
//
//  Created by 谢贤 on 2017/8/7.
//  Copyright © 2017年 谢贤. All rights reserved.
//

#import "DLBChooseSceneView.h"
@interface DLBChooseSceneView()
// 取消按钮点击
- (IBAction)cancelClick:(id)sender;


@end
@implementation DLBChooseSceneView

-(void)setSceneArray:(NSMutableArray *)sceneArray
{
    _sceneArray = sceneArray;

    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"id",
                         @"全部",@"name",@"",@"table_name",nil];
    NSMutableArray *tempArray = [NSMutableArray arrayWithObject:dic];
//    [sceneArray addObject:dic];
    [tempArray addObjectsFromArray:sceneArray];
    
    CGFloat btnH = 44.0;
    CGFloat btnW = 80.0;
    // 总列数
    NSInteger totalColumns = 3;
    // 间距
    NSInteger margin = (YLScreenW - btnW*totalColumns) / totalColumns;
    
    // 设置数据
    for (int i = 0; i < tempArray.count; i++) {
        // 列数
        NSInteger a = i % totalColumns;
        // 行数
        NSInteger b = i / totalColumns;
        NSDictionary *dic = tempArray[i];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.yl_width = btnW;
        btn.yl_height = btnH;
        btn.yl_x = margin*0.5 + (btnW + margin)*a;
        btn.yl_y =  60 + (btnH + 20)*b;
        btn.backgroundColor = [UIColor whiteColor];
        // 设置边框
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 6;
        
        btn.layer.borderWidth = 1;
        UIColor *borColor = HEXCOLOR(0xdcdcdc);
        btn.layer.borderColor = borColor.CGColor;
        
        [btn.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
        [btn setTitle:dic[@"name"] forState:UIControlStateNormal];
        [self addSubview:btn];
        
        // 添加点击事件
        btn.tag = [dic[@"id"] integerValue];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    self.btnBottom.constant = HOME_INDICATOR_HEIGHT;
}

// 点击事件
- (void)btnClick:(UIButton *)btn
{
    YLLogFunc
    YLLog(@"%ld",btn.tag);
    self.selSceneBlock(btn.tag);
}

// 取消按钮点击
- (IBAction)cancelClick:(id)sender {
    self.quitPaySel();
}
@end
